//
//  JDExtractConfirmAgainView.swift
//  DragonWallet
//
//  Created by volantPig on 2025/1/6.
//

import UIKit

class JDExtractConfirmAgainView: UIView {
    
    var confirmButtonSelected: (()->Void)?
    
    var containerView: UIView?
    var cancelButton: UIButton?
    var confirmButton: UIButton?
    var topLine: UIView?
    var titleLabel: UILabel?
    
//    var titleStr: String? {
//        didSet {
//            self.tipInfoLabel?.text = self.titleStr
//        }
//    }
    
    var userPortraitImageV: UIImageView?
    var nameTitle: UILabel?
    var nameLabel: UILabel?
    var rightTitle: UILabel?
    var extractNumberLabel: UILabel?
    
    override init(frame: CGRect) {
        super.init(frame: CGRectMake(0, 0, screenWidth, screenHeight))
        self.setupConfig()
        self.setupUIElements()
    }
    
    func setupConfig() {
        self.backgroundColor = color("#000000").withAlphaComponent(0.4)
    }
    
    func setupUIElements() {
        self.containerView = UIView()
        self.addSubview(self.containerView!)
        self.containerView?.snp.makeConstraints({ make in
            make.left.right.bottom.equalTo(self)
//            make.height.equalTo(255)
        })
        self.containerView?.backgroundColor = .white
        
        self.cancelButton = UIButton(type: .custom)
        self.containerView?.addSubview(self.cancelButton!)
        self.cancelButton?.snp.makeConstraints({ make in
            make.left.equalTo(self.containerView!).offset(12)
            make.right.equalTo(self.containerView!.snp.centerX).offset(-5)
            make.bottom.equalTo(self.containerView!).offset(-25)
            make.height.equalTo(50)
        })
        self.cancelButton?.layer.cornerRadius = 25
        self.cancelButton?.backgroundColor = color("#F5F6F8")
        self.cancelButton?.setTitle("取消", for: .normal)
        self.cancelButton?.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .regular)
        self.cancelButton?.setTitleColor(.black, for: .normal)
        self.cancelButton?.addTarget(self, action: #selector(cancelAction), for: .touchUpInside)
        
        self.confirmButton = UIButton(type: .custom)
        self.containerView?.addSubview(self.confirmButton!)
        self.confirmButton?.snp.makeConstraints({ make in
            make.right.equalTo(self.containerView!).offset(-12)
            make.left.equalTo(self.containerView!.snp.centerX).offset(5)
            make.bottom.equalTo(self.containerView!).offset(-25)
            make.height.equalTo(50)
        })
        self.confirmButton?.setTitle("确定", for: .normal)
        self.confirmButton?.layer.cornerRadius = 25
        self.confirmButton?.backgroundColor = color("#FA6161")
        self.confirmButton?.setTitleColor(.white, for: .normal)
        self.confirmButton?.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .regular)
        self.confirmButton?.addTarget(self, action: #selector(confirmAction), for: .touchUpInside)
        
        self.topLine = UIView()
        self.containerView?.addSubview(self.topLine!)
        self.topLine?.snp.makeConstraints({ make in
            make.left.equalTo(self.containerView!).offset(12)
            make.right.equalTo(self.containerView!).offset(-12)
            make.bottom.equalTo(self.cancelButton!.snp.top).offset(-134)
            make.height.equalTo(1)
        })
        self.topLine?.backgroundColor = .commonColor()
        
        self.titleLabel = UILabel()
        self.containerView?.addSubview(self.titleLabel!)
        self.titleLabel?.snp.makeConstraints({ make in
            make.centerX.equalTo(self.containerView!)
            make.bottom.equalTo(self.topLine!.snp.top).offset(-22)
            make.top.equalTo(self.containerView!).offset(22)
        })
        self.titleLabel?.text = "核对到账信息"
        self.titleLabel?.labelConfig(textAlignment: .center, font: UIFont.systemFont(ofSize: 16, weight: .semibold), textColor: color("#333333"), numberOfLines: 1)
        
        self.userPortraitImageV = UIImageView()
        self.containerView?.addSubview(self.userPortraitImageV!)
        self.userPortraitImageV?.snp.makeConstraints({ make in
            make.left.equalTo(self.containerView!).offset(22)
            make.top.equalTo(self.topLine!.snp.bottom).offset(32)
            make.size.equalTo(CGSizeMake(44, 44))
        })
        self.userPortraitImageV?.backgroundColor = .orange
        self.userPortraitImageV?.makeCorner(8)
        
//        var userPortraitImageV: UIImageView?
        self.nameTitle = UILabel()
        self.containerView?.addSubview(self.nameTitle!)
        self.nameTitle?.snp.makeConstraints({ make in
            make.left.equalTo(self.userPortraitImageV!.snp.right).offset(12)
            make.top.equalTo(self.userPortraitImageV!).offset(2)
            make.height.equalTo(17)
        })
        self.nameTitle?.text = "微信昵称"
        self.nameTitle?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 12, weight: .regular), textColor: color("#9DA1B2"), numberOfLines: 1)
        
        self.nameLabel = UILabel()
        self.containerView?.addSubview(self.nameLabel!)
        self.nameLabel?.snp.makeConstraints({ make in
            make.left.equalTo(self.nameTitle!)
            make.top.equalTo(self.nameTitle!.snp.bottom).offset(2)
            make.height.equalTo(22)
        })
        self.nameLabel?.text = "林子祥"
        self.nameLabel?.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 16, weight: .regular), textColor: color("#333333"), numberOfLines: 1)
        
//        var nameTitle: UILabel?
//        var nameLabel: UILabel?
//        var rightTitle: UILabel?
        self.rightTitle = UILabel()
        self.containerView?.addSubview(self.rightTitle!)
        self.rightTitle?.snp.makeConstraints({ make in
            make.right.equalTo(self.containerView!).offset(-22)
            make.centerY.equalTo(self.nameTitle!)
        })
        self.rightTitle?.text = "提现金额"
        self.rightTitle?.labelConfig(textAlignment: .right, font: UIFont.systemFont(ofSize: 12, weight: .regular), textColor: color("#9DA1B2"), numberOfLines: 1)
//        var extractNumberLabel: UILabel?
        
        self.extractNumberLabel = UILabel()
        self.containerView?.addSubview(self.extractNumberLabel!)
        self.extractNumberLabel?.snp.makeConstraints({ make in
            make.centerY.equalTo(self.nameLabel!)
            make.right.equalTo(self.rightTitle!)
        })
        self.extractNumberLabel?.text = "￥50.00"
        self.extractNumberLabel?.labelConfig(textAlignment: .right, font: UIFont.systemFont(ofSize: 18, weight: .semibold), textColor: color("#333333"), numberOfLines: 1)
        
        self.extractNumberLabel?.priceString(UIFont.systemFont(ofSize: 12, weight: .semibold), UIFont.systemFont(ofSize: 18, weight: .semibold))

    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func cancelAction() {
        self.removeFromSuperview()
    }
    
    @objc func confirmAction() {
        self.cancelAction()
        self.confirmButtonSelected?()
    }
    
}
